<?php

class ReplicaBN  {
	
	public function generarPK() {	
		$criteria = new Criteria(ReplicaPeer::DATABASE_NAME);
		$n = ReplicaPeer::doCount($criteria);
		$n++;
		return $n;
	}
	
	public function obtenerMuestras($codUe) {
	
		$criteria = new Criteria(ReplicaPeer::DATABASE_NAME);
		$criteria->add(ReplicaPeer::CODUE, $codUe);
	
		$aObj = ReplicaPeer::doSelect($criteria);
	
		$replicas = array();
	
		foreach($aObj as $obj) {
			$replicas[$obj->getCodReplica()] = $obj;
		}
	
		return $replicas;
	}
	
	
	public function crearReplica(Replica $entity) {
		
		$pk = $this->generarPK();
		 
		$entity->setCodReplica($pk);
		$entity->setEstado("1");
		
		$resultado = $entity->save();
		
		if($resultado) {
			$this->crearBaseReplica();
		}
		
		if($resultado) {
			$resultado = grabarMultimedia("3", $pk, "1" );
		}
		
		return $resultado;
		
	}
	
	public function actualizarReplica(Replica $entity) {

		$resultado = $entity->save();

		$this->actualizarBaseReplica();	


		$resultado = grabarMultimedia("3", $entity->getCodReplica(), "1" );
		
		return 1;		
	}
	
	public function eliminarReplica($codReplica) {
		
	}
	
	public function crearBaseReplica() {
		//$this->actualizarMM($this->codUe); //objUE->getCodue());
	
	}
	
	public function actualizarBaseReplica() {
		//$this->actualizarMM($this->codUe); //objUE->getCodue());
	
	}
	
	
	public static function obtenerPorPK($pk){
	
		$entity = ReplicaPeer::retrieveByPK($pk);
	
	
		return $entity;
	
	}
	
	function elimina_mm($categoria, $tipo_material, $cod_material, $cod_mm) {
		$criteria = new Criteria(MaterialMmPeer::DATABASE_NAME);
		$criteria->add(MaterialMmPeer::CATEGORIA, $categoria);
		$criteria->add(MaterialMmPeer::TIPO_MATERIAL, $tipo_material);
		$criteria->add(MaterialMmPeer::COD_MATERIAL, $cod_material);
		$criteria->add(MaterialMmPeer::COD_MM, $cod_mm);
		
		$aObj = MaterialMmPeer::doSelect($criteria);
		
		foreach($aObj as $obj) {
			$obj->delete();
		}	
		
		return 1;
	}
}
?>